package com.ks.app.admin.action;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import com.ks.app.admin.hibernate.KsUser;
import com.ks.app.admin.hibernate.KsResolution;
import com.ks.app.admin.service.KsresolutionService;
import com.ks.app.admin.util.Pager;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.interceptor.ServletRequestAware;

@ParentPackage("struts-default")
@Namespace("")
@InterceptorRef("defaultStack")
@Results( {
		@Result(name = "success", location = "/WEB-INF/admin/main.html"),
		@Result(name = "quit", location = "/WEB-INF/admin/send.jsp"),
		@Result(name = "error", location = "/WEB-INF/admin/error.jsp"),
		@Result(name = "ResolutionInfo", location = "/WEB-INF/admin/Resolution/ResolutionInfo.jsp"),
		@Result(name = "addResolution", location = "/WEB-INF/admin/Resolution/addResolution.jsp"),
		@Result(name = "IntiEditResolution", location = "/WEB-INF/admin/Resolution/EditResolution.jsp")

})
public class KsResolutionAction implements ServletRequestAware{
	private HttpServletRequest request;
	private String username;	

	@Resource
	private KsresolutionService ksresolutionService;
	
	private HttpSession session;
	private String pno;
	private KsResolution resolutioninfo;
	@SuppressWarnings("unused")
	private KsUser sessuser;	
	
	public KsResolution getResolutioninfo() {
		return resolutioninfo;
	}
	public void setResolutioninfo(KsResolution resolutioninfo) {
		this.resolutioninfo = resolutioninfo;
	}
	
	public String getPno() {
		return pno;
	}
	public void setPno(String pno) {
		this.pno = pno;
	}	
	
	public HttpSession getSession() {
		return session;

	}
	public void setSession(HttpSession session) {
		this.session = session;
	}	
	public void setServletRequest(HttpServletRequest arg0) {
		request=arg0;
	}
	public KsUser getSessuser() {
		return sessuser;
	}

	public void setSessuser(KsUser sessuser) {
		this.sessuser = sessuser;
	}
	@Action("/admin/Resolution/ResolutionInfo")
	public String ResolutionInfo()//根据条件分页展示分辨率数据
	{		
		 try 
		 {
			pno = request.getParameter("pno") == null ? "1" : request
						.getParameter("pno").toString().trim();
			String rid=request.getParameter("uiid");
			Pager pager = new Pager();
			int iPageNo = 1;
			try{
				iPageNo = Integer.parseInt(pno);
			}
			catch( Exception e ){        	
			}
			pager.setCntOfPage(20);
			pager.setCurPage(iPageNo);
			List<KsResolution> querylist=ksresolutionService.GetKsResolutionList(rid, pager);
			request.setAttribute("list_ResolutionInfo", querylist);
			request.setAttribute("PAGER", pager);
			return "ResolutionInfo";
		}
		 catch (Exception e)
		 {
			return Error();
		}
	}
	@Action("/admin/Resolution/addResolution")
	public String addResolution()//进入添加分辨率页面
    {  		
		try {
			//List<KsResolution> querylist=ksResolutionService.GetKsResolution(null);
			//request.setAttribute("list_ResolutionInfo", querylist);			
			return "addResolution";
		}
		catch (Exception e)
		{
			return Error();
		}	
    }		
	
	@Action("/admin/Resolution/Error")
	public String Error()//页面抛错跳转页面
	{			
		return "error";
	}	

	@Action("/admin/Resolution/EditResolution")
	public String EditResolution()//修改分辨率操作页面
    {   			
		try 
		{
			//	System.out.println("userinfo()=="+userinfo.getKsUserId()+";n="+username);
				//List<KsUser> querylist=userService.getKsUser();
				//request.setAttribute("list_UserInfo", querylist);
				username=request.getSession().getAttribute("userinfo").toString().trim();
				ksresolutionService.updateKsResolution(resolutioninfo,username);
				return ResolutionInfo();
		} 
		catch (Exception e) {
			return Error();
		}    	
    }
	@Action("/admin/Resolution/IntiEditResolution")
	public String IntiEditResolution()//初始化修改分辨率页面
	{			
		try {
			//List<KsResolution> querylist0=ksresolutionService.GetKsResolution(null);
			//request.setAttribute("list_ResolutionInfo", querylist0);
			
			String id=request.getParameter("uid");
			List<KsResolution> querylist=ksresolutionService.GetKsResolution(id);
			if(querylist.size()>0)
			{
				resolutioninfo=querylist.get(0);			
			}		
			return "IntiEditResolution";
		} 
		catch (Exception e) 
		{
			return Error();
		}
	}
	@Action("/admin/Resolution/SaveResolution")
	public String SaveResolution()//保存分辨率数据
    {   		
		try {
			//resolutioninfo.setKsCreateTime(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));			
			username=request.getSession().getAttribute("userinfo").toString().trim();
			ksresolutionService.addKsResolution(resolutioninfo,username);
			return  ResolutionInfo();
		} 
		catch (Exception e) 
		{
			//e.printStackTrace();
			return Error();
		}   	
    }
	@Action("/admin/Resolution/DeleteResolution")
	public String DeleteResolution()//删除分辨率数据
	{	 
		try {
			username=request.getSession().getAttribute("userinfo").toString().trim();
			String idlist=request.getParameter("uid");	
			ksresolutionService.deleteKsResolution(idlist,username);
			return ResolutionInfo();
		} catch (Exception e)
		{			
			return Error();
		}	
	}
}